
def signal(df, n, factor_name):
    df['bbi'] = (df['close'].rolling(n, min_periods=1).mean() +
                 df['close'].rolling(2 * n, min_periods=1).mean() +
                 df['close'].rolling(4 * n, min_periods=1).mean() +
                 df['close'].rolling(8 * n, min_periods=1).mean()) / 4
    df['bbi_bias'] = df['close'] / df['bbi']

    df['振幅'] = (df['high'] - df['low']) / df['open']
    df['factor'] = df['quote_volume'] / df['振幅']

    df[factor_name] = df['factor'].rolling(n, min_periods=1).std() * df['bbi_bias']

    del df['bbi'], df['bbi_bias'], df['振幅'], df['factor']

    return df
